﻿using System;
using Token.Piker.BLL;
using System.Web.Security;
using Token.Piker.Common;

namespace Token.Piker.Web.Admin.User
{
    public partial class Show : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
            {
                string strid = Request.Params["id"];
                int ID = (Convert.ToInt32(strid));
                ViewState["ID"] = ID;
                ShowInfo(ID);
            }
        }

        protected void lkbPassword_Click(object sender, EventArgs e)
        {
            int id = Convert.ToInt32(ViewState["ID"]);
            UserBLL userBLL = new UserBLL();
            Token.Piker.Model.User user = userBLL.GetModel(id);
            string password = "PikerUser"+DateTime.Now.ToShortDateString();
            string newpassword = FormsAuthentication.HashPasswordForStoringInConfigFile(password, "MD5");
            user.UserPwd = newpassword;
            if (userBLL.Update(user))
            {
                MessageBox.Show(this.Page, "重置用户密码成功，新的密码为：" + password);
            }
            else
            {
                MessageBox.Show(this.Page, "重置用户密码失败！");
            }
        }

        private void ShowInfo(int ID)
        {
            Token.Piker.BLL.UserBLL bll = new Token.Piker.BLL.UserBLL();
            Token.Piker.Model.User model = bll.GetModel(ID);
            this.lblID.Text = model.ID.ToString();
            this.lblUserName.Text = model.UserName;
            this.lblRegisterTime.Text = model.RegisterTime.ToString();
            this.lblLastLogTime.Text = model.LastLogTime.ToString();
            imageUserFace.ImageUrl = model.UserPic;
            this.lblPhone.Text = model.Phone;
            this.lblBirthday.Text = Convert.ToDateTime(model.Birthday).ToLongDateString();
            this.lblGender.Text = model.Gender.ToString()=="0"?"男":"女";
            this.lblQQ.Text = model.QQ;
            this.lblEmail.Text = model.Email;
            this.lblHomeAddr.Text = model.HomeAddr;
            this.lblSpeciality.Text = model.Speciality;
            this.lblFlag.Text = model.Flag.ToString()=="0"?"正常":"禁用";
        }
    }
}